package com.example.springioc1;

import com.example.springioc1.Controller.UserController;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

//@ComponentScan(basePackages = "com.example.springioc1")//修改扫描目录（默认是当前目录包括当前目录的子目录）
@SpringBootApplication
public class SpringIoc1Application {

    public static void main(String[] args) {
       ConfigurableApplicationContext context =  SpringApplication.run(SpringIoc1Application.class, args);
        /*HelloController bean = context.getBean(HelloController.class);
        bean.sayHi();
        //Bean的name是小驼峰的类名
        HelloController helloController = (HelloController) context.getBean("helloController");
        helloController.sayHi();

        HelloController bean1 = context.getBean("helloController", HelloController.class);
        bean1.sayHi();

        //当前两个字母均为大写时，Bean的名称就是原来的类名
        UController uController = (UController) context.getBean("UController");
        uController.sayHi();

        //JDK中的命名方式
        System.out.println(Introspector.decapitalize("HelloControoler"));
        System.out.println(Introspector.decapitalize("UControoler"));

        UserSevice bean2 = context.getBean(UserSevice.class);
        bean2.doSevice();
        UserComponent bean3 = context.getBean(UserComponent.class);
        bean3.doComponent();
        UserConfig bean4 = context.getBean(UserConfig.class);
        bean4.doConfig();
        UserRepo bean5 = context.getBean(UserRepo.class);
        bean5.doRepostitory();

        //使用@Bean注解时，Bean的名称就是方法名
        UserInfo getUserInfo = (UserInfo) context.getBean("getUserInfo");
        System.out.println(getUserInfo);
        UserInfo getUserInfo1 = (UserInfo) context.getBean("getUserInfo1");
        System.out.println(getUserInfo);
        UserInfo getUserInfo2 = (UserInfo) context.getBean("getUserInfo2");
        System.out.println(getUserInfo);*/

        //根据类型和名称去查找当前对象的
        UserController bean6 = context.getBean(UserController.class);
        bean6.sayHi();

    }
}
